<template>
  <div
    class="cardWrapper"
    :id="`menuScroll${scrollFirstIndex}-${componentsIndex}`"
    v-if="layerItem.children.length"
  >
    <div class="cardTitleContainer">
      <img
        src="https://img3.job1001.com/data_center/images/position_item_icon.png"
        alt="Icon"
        class="position_item_icon"
      />
      <div class="cardTitle">{{ layerItem.title }}</div>
    </div>
    <div class="layerList">
      <el-row
        class="demo-autocomplete"
        :key="index"
        v-for="(item, index) in layerItem.children || layerList"
      >
        <!-- <div class="demo-autocomplete-content" v-if="handleDisplayContent(item)"> -->
        <div class="demo-autocomplete-content">
          <div class="controlLine" :id="`scroll${componentsIndex}-${index}`">
            <span class="tinyTitle">
              <div class="titleFlag"></div>
              {{ item.title }}
            </span>
            <div class="line"></div>
          </div>
          <div class="chanceContainer" v-loading="loading">
            <div class="chanceForm">
              <el-form ref="form" :model="form">
                <el-form-item label="区域名称：">
                  <regoinSearch
                    ref="regionRef"
                    @onRegionChange="onRegionChange"
                  />
                </el-form-item>
                <el-form-item label="行业名称：">
                  <IndustryCheckbox
                    :limitNum="1"
                    ref="regionRef"
                    disableDefault
                    @onIndustryChange="onIndustryChange"
                  />
                </el-form-item>
                <el-form-item label="企业规模：">
                  <companyCheckbox
                    :limitNum="1"
                    ref="regionRef"
                    deleteAll
                    disableDefault
                    @onCompanyChange="onCompanyChange"
                  />
                </el-form-item>
                <el-form-item label="招聘对象：">
                  <targetCheckbox
                    :limitNum="1"
                    ref="regionRef"
                    disableDefault
                    @onTargetChange="onTargetChange"
                  />
                </el-form-item>
                <el-form-item label="学历要求：">
                  <EduCheckbox
                    :limitNum="1"
                    ref="regionRef"
                    disableDefault
                    @onTargetChange="onEduChange"
                  />
                </el-form-item>
                <!-- <el-form-item label="经验要求：">
                  <workCheckbox
                    :limitNum="1"
                    ref="workYearRef"
                    @onIndustryChange="onWorkYearChange"
                  />
                </el-form-item> -->
              </el-form>
            </div>
            <div class="chanceContent">
              <template v-if="chanceList && chanceList.length">
                <div
                  class="position-item"
                  v-for="(item, index) in chanceList"
                  :key="index"
                  @click="handleClickJob(item)"
                >
                  <div class="position-left">
                    <p class="position-title text-overflow" :title="item.jtzw">
                      {{ item.positionName }}
                    </p>
                    <p class="condition">
                      <span class="condition-item">{{ item.workExp }}</span>
                      <span class="divider-vertical" v-if="item.eduName"></span>
                      <span class="condition-item">{{ item.eduName }}</span>
                      <span class="divider-vertical" v-if="item.region"></span>
                      <span class="condition-item">{{ item.region }}</span>
                      <span class="divider-vertical"></span>
                      <span
                        class="condition-item salary"
                        v-if="item.salaryDown && item.salaryUp"
                        >{{ item.salaryDown + " - " + item.salaryUp }}</span
                      >
                      <span class="condition-item salary" v-else>面议</span>
                    </p>
                    <p class="update-time">
                      更新于：{{
                        item.statisticalCalculationTime &&
                        new Date(item.statisticalCalculationTime)
                          .toISOString()
                          .split("T")[0]
                      }}
                    </p>
                  </div>
                  <div class="position-middle">
                    <p class="company-name text-overflow" :title="item.comName">
                      {{ item.comName }}
                    </p>
                    <p
                      class="company-address text-overflow"
                      :title="item.workPlace"
                    >
                      {{ item.workPlace }}
                    </p>
                    <p class="company-welfare">
                      <span
                        class="welfare-item"
                        v-for="fl in item.fldy"
                        :key="fl"
                        >{{ fl }}</span
                      >
                    </p>
                  </div>
                  <div class="position-right">
                    <p>
                      <!-- <img :src="item.logo" alt="" class="company-logo"> -->
                    </p>
                    <!-- <el-button color="#fa4144" size="small">申请职位</el-button> -->
                  </div>
                </div>
              </template>
              <el-empty class="empty" description="暂无数据" v-else></el-empty>
            </div>
            <div class="pagination">
              <el-pagination
                background
                layout="total, sizes, prev, pager, next, jumper"
                :current-page="tablePage.pageNum"
                :page-size="tablePage.pageSize"
                :page-sizes="pageSizes"
                :total="tablePage.total"
                @size-change="handleSizeChange"
                @current-change="handlePageChange"
              />
            </div>
          </div>
        </div>
      </el-row>
    </div>
  </div>
</template>

<script>
import { reqChartJobs } from "@/api/position-detail.js";
import regoinSearch from "@/views/position/components/regoinSearch";
import companyCheckbox from "@/components/companyCheckbox/index";
import IndustryCheckbox from "@/components/IndustryCheckbox/index";
import targetCheckbox from "@/components/targetCheckbox/index";
import EduCheckbox from "@/components/EduCheckbox/index";
import workCheckbox from "@/views/position/salaryOverview/detailSalary/components/workSalaryChanges/workCheckbox";
export default {
  name: "workChangeSecond",
  components: {
    regoinSearch,
    companyCheckbox,
    IndustryCheckbox,
    targetCheckbox,
    EduCheckbox,
    workCheckbox,
  },
  props: {
    layerList: {
      type: Array,
      default: () => [],
    },
    layerItem: {
      type: Object,
      default: () => {},
    },
    topId: {
      type: String,
      required: true,
    },
    isSuperToken: {
      type: Boolean,
      default: false,
    },
    scrollFirstIndex: {
      type: [String, Number],
      default: 0,
    },
    aiCreateStatus: {
      type: Boolean,
      default: false,
    },
  },
  watch: {
    layerItem: {
      handler(newValue, oldValue) {
        if (newValue.layerId) {
          this.layerList.forEach((item, index) => {
            if (item.layerId == newValue.layerId) {
              this.componentsIndex = index;
            }
          });
        }
      },
      immediate: true,
    },
  },
  data() {
    return {
      loading: false,
      form: {},
      chanceList: [],
      regionList: [],
      selectedIndustryList: [],
      selectedCompanyList: [],
      selectedTargetList: [],
      selectedEduList: [],
      selectedWorkYearList: [],
      tablePage: {
        pageNum: 1, // 第几页
        pageSize: 10, // 每页多少条
        total: 0, // 总记录数
      },

      pageSizes: [10, 20, 30],
      positionId: this.$route.query.id,
      componentsIndex: "", //用来标记组件下标，滚动用
    };
  },
  methods: {
    handleClickJob(item) {
      const jobDetail = {
        employerRequirements: item.positionDemand,
        cname: item.comName,
        trade: item.industry,
        yuangong: item.comScale,
        jtzw: item.positionName,
        regionid_name: item.region,
        edus: item.eduName,
        rctypes: item.workExp,
        xzdy: `${item.salaryDown}-${item.salaryUp}元/月`,
        id: item.ylPositionId,
        activeTime: item.publishTime,
      };
      localStorage.setItem("jobDetail", JSON.stringify(jobDetail));
      let routeData = this.$router.resolve({
        path: `job-detail?comId=${item.comId}&isShowQRCode=false`,
      });
      window.open(routeData.href, "_blank");
    },
    fetchData() {
      this.loading = true;
      const params = {
        ylPositionId: this.positionId,
        pageNo: this.tablePage.pageNum,
        pageSize: this.tablePage.pageSize,
      };
      if (this.regionList != []) {
        params.regionId = this.regionList.join(",");
      }
      if (this.selectedIndustryList != []) {
        params.industryId = this.selectedIndustryList.join(",");
      }
      if (this.selectedCompanyList != []) {
        params.comScaleId = this.selectedCompanyList.join(",");
      }
      if (this.selectedTargetList != []) {
        params.isGraduate = this.selectedTargetList.join(",");
      }
      if (this.selectedTargetList != []) {
        params.eduCode = this.selectedEduList.join(",");
      }
      if (this.selectBetweenTime != null && this.selectBetweenTime != "") {
        params.selectBeginTime = this.selectBetweenTime[0];
        params.selectEndTime = this.selectBetweenTime[1];
      }
      if (this.selectedWorkYearList != []) {
        params.workYear = this.selectedWorkYearList[0];
      }
      console.log("--------reqChartJobs------------->params", params);
      
      reqChartJobs(params)
        .then((res) => {
          if (res.code == 200) {
            this.chanceList = res.data.map(function (v) {
              if (v.salaryUp & v.salaryDown) {
                v.salaryUp = (v.salaryUp / 1000).toFixed(1) + "k";
                v.salaryDown = (v.salaryDown / 1000).toFixed(1) + "k";
              }
              return v;
            });
            this.tablePage.total = res.pageparam.sums;
          }
        })
        .catch((e) => {
          //console.log("e");
        })
        .finally(() => {
          this.loading = false;
        });
    },
    onRegionChange(val) {
      //console.log("onRegionChange--------->", val.label);
      this.regionList = [val.value];
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    onTargetChange(val) {
      this.selectedTargetList = [];
      if (val && val.length) {
        val.forEach((item) => {
          this.selectedTargetList.push(item.split("-")[0]);
        });
      } else {
        this.selectedTargetList = [];
      }
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    onEduChange(val) {
      this.selectedEduList = [];
      if (val && val.length) {
        val.forEach((item) => {
          this.selectedEduList.push(item.split("-")[0]);
        });
      } else {
        this.selectedEduList = [];
      }
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    onWorkYearChange(val) {
      this.selectedWorkYearList = [];
      if (val && val.length) {
        this.selectedWorkYearList = val[0].split("-")[1];
        this.selectedWorkYearList = [];
        val.forEach((item) => {
          this.selectedWorkYearList.push(item.split("-")[0]);
        });
      } else {
        this.selectedWorkYearList = [];
      }
      console.log("--------->onWorkYearChange", val);
      
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    onCompanyChange(val) {
      this.selectedCompanyList = [];
      if (val && val.length) {
        val.forEach((item) => {
          this.selectedCompanyList.push(item.split("-")[0]);
        });
      } else {
        this.selectedCompanyList = [];
      }
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    onIndustryChange(val) {
      //console.log("onIndustryChange", val);
      this.selectedIndustryList = [];
      if (val && val.length) {
        val.forEach((item) => {
          this.selectedIndustryList.push(item.split("-")[0]);
        });
      } else {
        this.selectedIndustryList = [];
      }
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
    handlePageChange(currentPage) {
      this.tablePage.pageNum = currentPage;
      this.fetchData();
    },
    handleSizeChange(pageSize) {
      this.tablePage.pageSize = pageSize;
      this.tablePage.pageNum = 1;
      this.fetchData();
    },
  },
};
</script>

<style lang="scss" scoped>
.cardWrapper {
  // position: relative;
  min-width: 800px;
  border-radius: 10px;
  border: 1px solid #cbdcfe;
  background-size: 110% 219px;
  background-position: -10px -10px;
  background-image: url("https://img3.job1001.com/data_center/images/salary_bg.png");
  background-repeat: no-repeat;
  padding: 20px;
  flex: 1;
  margin: 0;

  margin-bottom: 14px;
  margin-top: 20px;
  &::-webkit-scrollbar {
    width: 4px;
    background-color: #fff;
    border-radius: 4px;

    height: 4px;
  }
  &::-webkit-scrollbar-thumb {
    background-color: #d8d8d8;
    border-radius: 4px;
  }
  .cardTitleContainer {
    display: flex;
    align-items: center;
    margin-bottom: 16px;
    // position: sticky;
    top: 0;
    .cardTitle {
      height: 30px;
      font-size: 22px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 600;
      color: #000000;
      line-height: 30px;
      margin-right: 15px;
    }
    .position_item_icon {
      width: 39px;
      height: 40px;
      margin-right: 13px;
    }
  }

  .layerList {
    .demo-autocomplete {
      display: flex;
      .demo-autocomplete-content {
        flex: 1;
      }
      .positionPic {
        width: 140px;
        // height: 137px;
        border-radius: 16px;
        opacity: 0.77;
      }
    }
  }
  .titleFlag {
    width: 5px;
    height: 15px;
    border-radius: 3px;
    background: #4880ff;
    margin-right: 12px;
  }
  .controlLine {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    margin-bottom: 15px;
    .tinyTitle {
      display: flex;
      align-items: center;
      font-weight: bold;
      font-size: 18px;
      // margin-right: 24px;
    }
    .line {
      flex: 1;
      // height: 16px;
      margin-left: 14px;
      border-bottom: 1px solid #efefef;
    }
  }
}

.chanceContent {
  padding-top: 10px;
  .position-item {
    display: flex;
    margin-bottom: 12px;
    padding: 24px 12px;
    border: 1px solid #f3f3f3;
    border-radius: 8px;
    box-shadow: 0 8px 18px 1px #f3f3f3;
    cursor: pointer;
  }
  p {
    margin-top: 0;
    margin-bottom: 0;
  }
  .divider-vertical {
    border-left: 1px #dcdfe6 solid;
    display: inline-block;
    height: 1em;
    margin: 0 8px;
    position: relative;
    vertical-align: middle;
    width: 1px;
  }
  .position {
    &-left {
      width: 400px;

      .position-title {
        padding-bottom: 12px;
        font-size: 18px;
      }
    }

    &-middle {
      width: 350px;
      .company-name {
        padding-bottom: 12px;
        font-size: 16px;
      }

      .company-address {
        padding-bottom: 5px;
        font-size: 14px;
        line-height: 2;
        min-height: 28px;
        color: #999;
      }
    }

    &-right {
      width: 100px;
      text-align: center;

      .company-logo {
        margin-bottom: 12px;
        width: 71px;
        height: 43px;
      }
    }
  }

  .welfare-item {
    display: inline-block;
    padding: 0 5px;
    margin-right: 10px;
    margin-bottom: 5px;
    line-height: 18px;
    font-size: 12px;
    color: #666;
    border: solid 1px #c9c9c9;
    border-radius: 4px;
  }

  .condition {
    padding-bottom: 5px;
    font-size: 14px;
  }
  .condition-item {
    line-height: 2;
  }

  .update-time {
    margin-top: 2px;
    font-size: 12px;
    color: #a1a1a1;
  }
  .salary {
    color: red;
  }
}
.pagination {
  display: flex;
  justify-content: center;
  position: relative;
  margin-top: 24px;
}
::v-deep .el-form-item {
  display: flex;
  align-items: center;
  margin-bottom: 0;
}
::v-deep .el-form-item__label {
  display: flex;
  align-items: center;
  justify-content: center;
  // height: 27px;
  min-width: 90px !important;
}
::v-deep .el-button--primary {
  color: #fff;
  background: #0b6eff;
  border-color: #0b6eff;
}
::v-deep .el-button--primary.is-plain {
  color: #409eff;
  background: #fff;
  border-color: #b3d8ff;
}
</style>
